dnl Process this file with autoconf to produce a configure script.
dnl
AC_INIT([ffs],[1.0],[eisen@cc.gatech.edu])
AC_CONFIG_SRCDIR([ffs.c])
AC_CONFIG_AUX_DIR(../config)
AC_CONFIG_MACRO_DIR([../config])
AM_INIT_AUTOMAKE([ffs],[1.0])
AM_MAINTAINER_MODE
AM_CONFIG_HEADER(config.h)

dnl
dnl Find the machine type and setup the relevant links
AC_CANONICAL_HOST

AC_ARG_WITH(code-gen, 
[ --with-code-gen            Use dynamic code generation in
                            conversion operations.],,with_code_gen=yes)

IO_FILE_NAME=unix_io

dnl Configure libtool
AC_LIBTOOL_WIN32_DLL
AM_PROG_LIBTOOL
LIBTOOL="$LIBTOOL --silent"
AC_SUBST(LIBTOOL_DEPS)

dnl checks for programs
AC_PROG_INSTALL
AC_LN_S
test x"$ac_cv_prog_gcc" = xyes && CWARNFLAGS="-Wall"
if test "${enable_kernel_build+set}" != set; then
	AC_ADD_PIC_ARGS
fi
AC_SUBST(CWARNFLAGS)
AC_CHECK_PROGS(MAKEDEPEND, makedepend, :)
dnl
dnl checks for libraries

FFS_CONVERSION_GENERATION_DEFAULT=0
CERCS_REQUIRE_PACKAGE(atl,atl.h,libatl.la)
CERCS_REQUIRE_PACKAGE(cercs_env,cercs_env.h,libcercs_env.la)
CERCS_REQUIRE_PACKAGE(dill,dill.h,libdill.la)
AC_ARG_ENABLE(code_generation,AC_HELP_STRING([--enable-code-generation],
                            [faster conversions via dynamic code generation (default is YES)]),,enable_code_generation="yes")
if test "$enable_code_generation" = yes; then
DCG_LALIB="$cercs_cv_dill_link_dir/libdill.la"
FFS_CONVERSION_GENERATION_DEFAULT=1
fi

CPPFLAGS="$CPPFLAGS"
dnl
FFS_VERSION=`grep "FFS Version" $srcdir/../version.c | sed 's/.*FFS Version \([[^.]]*.[[^.]]*\).*/\1/'`
AC_DEFINE_UNQUOTED(FFS_CONVERSION_GENERATION_DEFAULT, $FFS_CONVERSION_GENERATION_DEFAULT, [Define with a boolean to specify if DCG conversions will be generated by default])
AC_SUBST(IO_FILE_NAME)
AC_SUBST(FFS_VERSION)
checkBoth=0
AC_CHECK_FUNC(connect, checkSocket=0, checkSocket=1)
if test "$checkSocket" = 1; then
    AC_CHECK_LIB(socket, connect, LIBS="$LIBS -lsocket", checkBoth=1)
fi
if test "$checkBoth" = 1; then
    oldLibs=$LIBS
    LIBS="$LIBS -lsocket -lnsl"
    AC_CHECK_FUNC(accept, checkNsl=0, [LIBS=$oldLibs;NO_SOCKET=true;
AC_DEFINE(NO_SOCKET,1,[Define if there is no socket support])])
fi
AC_CHECK_FUNC(gethostbyname, , AC_CHECK_LIB(nsl, getdomainname, [LIBS="$LIBS -lnsl"]))
AM_CONDITIONAL(NO_SOCKETS, test x$NO_SOCKET = xtrue)
AC_CHECK_FUNCS(fork getdomainname gethostbyname)
oldLibs=$LIBS
LIBS=""
AC_CHECK_FUNCS(strtof strtod strtold)
LIBS=$oldLibs
dnl
dnl checks for header files
AC_HEADER_STDC
AC_CHECK_HEADERS(string.h memory.h malloc.h unistd.h dill.h)
if test "$enable_code_generation" = yes; then
AC_DEFINE(DO_DCG,1,[Define if ffs should do dynamic code generation])
FFS_GEN_O="ffs_gen.lo"
fi

AC_SUBST(DCG_LIBRARY)
AC_SUBST(DCG_LIBNAME)
AC_SUBST(DCG_LALIB)
AC_SUBST(FFS_GEN_O)
AC_SUBST(DCG_WILD)
AC_SUBST(DCG_DEPEND)
dnl


dnl checks for typedefs, structures and compiler characteristics
AC_C_CONST
AC_C_BIGENDIAN_CROSS($bigendian_default)
AC_TYPE_SIZE_T
AC_COMPILE_CHECK_SIZEOF(size_t)
AC_COMPILE_CHECK_SIZEOF(off_t)
AC_COMPILE_CHECK_SIZEOF(int)
AC_COMPILE_CHECK_SIZEOF(long)
AC_COMPILE_CHECK_SIZEOF(long long)
AC_COMPILE_CHECK_SIZEOF(long double)
AC_COMPILE_CHECK_SIZEOF(float)
AC_COMPILE_CHECK_SIZEOF(double)

if test $ac_cv_sizeof_size_t -eq $ac_cv_sizeof_int ; then
   UIO_SIZE_T_TYPE="unsigned int"
elif test $ac_cv_sizeof_size_t -eq $ac_cv_sizeof_long; then
   UIO_SIZE_T_TYPE="unsigned long";
fi
AC_SUBST(UIO_SIZE_T_TYPE)
if test $ac_cv_sizeof_long -eq 8 ; then
   DATA_LEN_TYPE="long";
elif test $ac_cv_sizeof_long_long -eq 8 ; then
   DATA_LEN_TYPE="long long";
else
   DATA_LEN_TYPE="undefined";
fi
AC_SUBST(DATA_LEN_TYPE)
AC_DEFINE_UNQUOTED(DATA_LEN_TYPE,$DATA_LEN_TYPE, [Define as the 8-byte type to use for data length])
LIBS="$LIBS -lcercs_env"

if test -n "$cercs_cv_archive"; then
ARCH=$cercs_cv_archive
OUTPUT_TARGET=write_output
fi
AC_SUBST(ARCH)
AC_SUBST(OUTPUT_TARGET)
AC_DEFINE_UNQUOTED(ARCH,"$ARCH", [Define as a string to identify the machine architecture])
AC_ARG_WITH(format_server, [  --with-format-server=HOST    Which host will run the format server.],FORMAT_SERVER_HOST=$withval)

if test "x$FORMAT_SERVER_HOST" = "x"; then
   hostname=`hostname`
   domainname=""
   host_no_domain=`hostname|sed 's/\..*//g'`
   if test "$hostname" != "$host_no_domain"; then
      # A fully qualified hostname?
      domainname=`hostname|sed "s/$host_no_domain.//"`
      hostname=$host_no_domain
   fi
   if test x"$domainname" = "x"; then
	if eval dnsdomainname 2>/dev/null 1>/dev/null; then
	    # dnsdomainname command, try it
	    domainname=`dnsdomainname`
	fi
   fi
   if test x"$domainname" = "x"; then
	if eval domainname 2>/dev/null 1>/dev/null; then
	    domainname=`domainname`
	fi
   fi
   if test x"$hostname" = "x"; then
	hostname="localhost"
   fi
   if test x"$domainname" = "x"; then
      # domainname is still not set, try this
      domainname=[`nslookup $hostname 2>/dev/null | grep Name: | sed 's/.*: *[^.]*.//g'`]
   fi

   highdomain=`echo $domainname | sed 's/\./\\
./g' | tail -2 `
    highdomain=`echo $highdomain | sed 's/ //g'`
   if test "x$highdomain" = "x.gatech.edu"; then
      FORMAT_SERVER_HOST="formathost.cercs.gatech.edu";
      FORMAT_SERVICE_DOMAIN=".edu:.com:.gov:.mil:.net:.org:.us";
   else
      if test "x$domainname" != "x"; then
          FORMAT_SERVER_HOST=$hostname.$domainname
      else
          FORMAT_SERVER_HOST=$hostname
      fi
   fi
fi
AC_ARG_WITH(service_domain, [  --with-service-domain=DOMAINNAME	What domain the server will serve.],FORMAT_SERVICE_DOMAIN=$withval)
AC_DEFINE_UNQUOTED(FORMAT_SERVER_HOST, "$FORMAT_SERVER_HOST", [Define with the name of the host which will run the format server])
AC_DEFINE_UNQUOTED(FORMAT_SERVICE_DOMAIN, "$FORMAT_SERVICE_DOMAIN", [Define with the name of the domain which the format server will service])

AC_CONFIG_FILES([Makefile tests/Makefile progs/Makefile])
AC_OUTPUT

